package Demo_type3;

/**
 * @className: SingletonTest
 * @description: 枚举实现单例模式 推荐使用
 * @author: Jng
 * @date: 2022/7/19
 **/
public class SingletonTest {
    public static void main(String[] args) {
        Singleton instance = Singleton.INSTANCE;
        Singleton instance1 = Singleton.INSTANCE;
        System.out.println(instance==instance1);
        instance.sayOk();
    }
}

enum Singleton{
    INSTANCE;
    public void sayOk(){
        System.out.println("ok~");
    }
}